<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" version="-//W3C//DTD XHTML 1.1//EN" dir="ltr">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Chained services Example</title>
    <link href="css/samples.css" rel="stylesheet" type="text/css">
    <?php
        require_once("lib/jsonsscli.php");
        ini_set("error_reporting", false);
    ?>
</head>
<body><div id="page-content">

    <h1>Chained services Example</h1>

    <h3>Service exchange log</h3>
    <pre class="console"><?php 

    JSONSSProxy::initLibrary();

    $urlsrc = "http://" . $_SERVER["SERVER_NAME"] . dirname($_SERVER["SCRIPT_NAME"]) . "/source.php";
    echo "SourceService URL = " . $urlsrc . "\r\n";
    $urldrn = "http://" . $_SERVER["SERVER_NAME"] . dirname($_SERVER["SCRIPT_NAME"]) . "/drain.php";
    echo "DrainService URL = " . $urldrn . "\r\n";

    try { 

        $proxysrc = JSONSSProxy::fromUrl($urlsrc);
        echo "Got source proxy object: SourceService.serviceUrl = " . $proxysrc->SourceService->serviceUrl . "\r\n";

        $proxydrn = JSONSSProxy::fromUrl($urldrn);
        echo "Got drain proxy object: DrainService.serviceUrl = " . $proxydrn->DrainService->serviceUrl . "\r\n";

        $msg = $proxysrc->SourceService->CreateMessage();
        echo "SourceService.CreateMessage() returns: " . $msg . "\r\n";

        echo "Trying to dispose message to DrainService...\r\n";
        $proxydrn->DrainService->DisposeMessage($msg);
        echo "DrainService.DisposeMessage() succeed\r\n";

    } catch (Exception $x) { 
        echo "Ooops! Exception: ". $x->getMessage() . "\r\n"; 
    } 

    try { 

        echo "Trying to dispose message to DrainService again...\r\n";
        $proxydrn->DrainService->DisposeMessage($msg);
        echo "Ooops! DrainService.DisposeMessage() succeed\r\n";
    } catch (Exception $x) { 
        echo "Fine. Exception: ". $x->getMessage() . "\r\n"; 
    } 

    JSONSSProxy::shutdownLibrary();

    ?></pre>
</div></body>
</html>
